package org.lql.algo.codecrush.hot100.backtrack;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: liangqinglong
 * @date: 2025-08-31 10:48
 * @description: 22. 括号生成 <a href="https://leetcode.cn/problems/generate-parentheses/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class GenerateParenthesis {

	public List<String> generateParenthesis(int n) {
		if (n == 0) {
			return Collections.singletonList("");
		}
		List<String> res = new ArrayList<>();
		for (int i = 1; i <= n; i++) {
			List<String> left = generateParenthesis(i - 1);
			List<String> right = generateParenthesis(n - i);
			for (String l : left) {
				for (String r : right) {
					res.add("(" + l + ")" + r);
				}
			}
		}
		return res;
	}

	public static void main(String[] args) {
		GenerateParenthesis generateParenthesis = new GenerateParenthesis();
		System.out.println(generateParenthesis.generateParenthesis(3));
	}
}
